package com.blog.controller.frontpage;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.blog.controller.base.BaseServlet;
import com.blog.entity.SupportEntity;
import com.blog.entity.UserEntity;
import com.blog.service.frontpage.ArticleService;
import com.blog.service.frontpage.SupportService;



@WebServlet("/aboutNum")
public class ArticleServlet extends BaseServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// 获得文章id和点赞人id
		String articleid = (String) req.getSession().getAttribute("titleid");
		UserEntity user = (UserEntity) req.getSession().getAttribute("user");
		SupportService service = new SupportService();
		if (articleid != null && !articleid.isEmpty() && user != null) {
			SupportEntity isUser = service.querySupportNumber(Integer.parseInt(articleid));
			System.out.println(isUser);
			if(isUser==null) {
				service.updateSupportNumber(Integer.parseInt(articleid));
				int insertSupportNumber = service.insertSupportNumber(user.getUser_id(), Integer.parseInt(articleid));
			}
		}
	}
}
